package de.tabiteuea.gui.models;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Model that holds all project informations and user inputs. See class
 * attributes for further information.
 * 
 * @author Sebastian Lippert
 * 
 */

public class InputModel {

	/**
	 * Name of the project
	 */
	private String projectName;
	/**
	 * Name of the file containing the corpus
	 */
	private String fileName;
	/**
	 * Absolute path to file containing the corpus
	 */
	private String filePath;
	/**
	 * Marks if the analysis should use the baseform of the input;
	 */
	private boolean useBaseform;
	/**
	 * Sequence that indicates the end of one word (could be a regular
	 * expression)
	 */
	private String wordDelimiter;
	/**
	 * Sequence that indicates the end of one sentence (could be a regular
	 * expression)
	 */
	private String sentenceDelimiter;
	/**
	 * Absolute path to the *.tabi project file
	 */
	private String savePath;
	/**
	 * Raw parsed text from the input file
	 */
	private String corpus;
	/**
	 * List of words for the word coverage calculation
	 */
	private List<String> wordList;
	/**
	 * Language of the corpus
	 */
	private Language textLanguage;
	/**
	 * Marks the wordDelimiter as regular expression or not
	 */
	private boolean wordDelIsRegExp;
	/**
	 * Marks the sentenceDelimiter as regular expression or not
	 */
	private boolean senDelIsRegExp;

	/**
	 * Empty Constructor
	 */
	public InputModel() {
	}

	/**
	 * Basic Constructor
	 * 
	 * @param projectName
	 *            Name of the project
	 * @param filePath
	 *            Absolute path to input file
	 * @param fileName
	 *            Name of the input file
	 */

	public InputModel(String projectName, String filePath, String fileName) {
		this.projectName = projectName;
		this.filePath = filePath;
		this.fileName = fileName;
	}

	/**
	 * Getter for project name
	 * 
	 * @return Project name
	 */

	public String getProjectName() {
		if (projectName == null)
			return new String();

		return projectName;
	}

	/**
	 * Setter for project name
	 * 
	 * @param projectName
	 *            New name for the project
	 */

	public void setProjectName(String projectName) {
		this.projectName = projectName;
	}

	/**
	 * Getter for file name
	 * 
	 * @return Name of the file
	 */

	public String getFileName() {
		if (fileName == null)
			return new String();

		return fileName;
	}

	/**
	 * Setter for file name
	 * 
	 * @param fileName
	 *            New file name
	 */

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	/**
	 * Getter for file path
	 * 
	 * @return Absolute path to the file
	 */

	public String getFilePath() {
		if (filePath == null)
			return new String();

		return filePath;
	}

	/**
	 * Setter for file path
	 * 
	 * @param filePath
	 *            New file path
	 */

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}

	/**
	 * Getter for word delimiter
	 * 
	 * @return Word delimiter
	 */
	public String getWordDelimiter() {
		if (wordDelimiter == null)
			return new String();

		return wordDelimiter;
	}

	/**
	 * Getter for indication whether the input should be reduced to its base
	 * form or not
	 * 
	 * @return Boolean
	 */

	public boolean isUseBaseform() {
		return useBaseform;
	}

	/**
	 * Setter for boolean whether the input should be reduced to its base form
	 * or not
	 * 
	 * @param useBaseform
	 *            Boolean
	 */

	public void setUseBaseform(boolean useBaseform) {
		this.useBaseform = useBaseform;
	}

	/**
	 * 
	 * Setter for word delimiter
	 * 
	 * @param wordDelimiter
	 *            New word delimiter
	 */

	public void setWordDelimiter(String wordDelimiter) {
		this.wordDelimiter = wordDelimiter;
	}

	/**
	 * Getter for sentence delimiter
	 * 
	 * @return Sentence delimiter
	 */

	public String getSentenceDelimiter() {
		if (sentenceDelimiter == null)
			return new String();

		return sentenceDelimiter;
	}

	/**
	 * 
	 * Setter for sentence delimiter
	 * 
	 * @param sentenceDelimiter
	 *            New sentence delimiter
	 */

	public void setSentenceDelimiter(String sentenceDelimiter) {
		this.sentenceDelimiter = sentenceDelimiter;
	}

	/**
	 * Getter for indication whether the word delimiter is an regular expression
	 * or not
	 * 
	 * @return Boolean
	 */

	public boolean isWordDelIsRegExp() {
		return wordDelIsRegExp;
	}

	/**
	 * Setter for boolean whether the word delimiter is an regular expression or
	 * not
	 * 
	 * @param wordDelIsRegExp
	 *            Boolean
	 */

	public void setWordDelIsRegExp(boolean wordDelIsRegExp) {
		this.wordDelIsRegExp = wordDelIsRegExp;
	}

	/**
	 * Getter for indication whether the sentence delimiter is an regular
	 * expression or not
	 * 
	 * @return Boolean
	 */

	public boolean isSenDelIsRegExp() {
		return senDelIsRegExp;
	}

	/**
	 * Setter for boolean whether the sentence delimiter is an regular
	 * expression or not
	 * 
	 * @param wordDelIsRegExp
	 *            Boolean
	 */

	public void setSenDelIsRegExp(boolean senDelIsRegExp) {
		this.senDelIsRegExp = senDelIsRegExp;
	}

	/**
	 * Getter for wordList that is used for word coverage calculation
	 * 
	 * @return WordList
	 */

	public List<String> getWordList() {
		if (wordList == null)
			return Collections.emptyList();

		return wordList;
	}

	/**
	 * Setter for wordList that is used for word coverage calculation
	 * 
	 * @param wordList
	 *            New word list
	 */

	public void setWordList(List<String> wordList) {
		this.wordList = wordList;
	}

	/**
	 * Add a word to the word list that is used for word coverage calculation
	 * 
	 * @param word
	 *            New word
	 */

	public void addWordToWordList(String word) {
		if (wordList == null)
			wordList = new ArrayList<String>();

		wordList.add(word);
	}

	/**
	 * Add a word to the word list that is used for word coverage calculation
	 * 
	 * @param word
	 *            New word
	 * @param index
	 *            Position where the word should be insert
	 */

	public void addWordToWordList(String word, int index) {
		if (wordList == null)
			wordList = new ArrayList<String>();

		wordList.add(index, word);
	}

	/**
	 * Remove a word from the word list that is used for word coverage
	 * calculation
	 * 
	 * @param word
	 *            Word that should be removed
	 */

	public void removeWordFromWordList(String word) {
		if (wordList == null)
			return;

		wordList.remove(word);
	}

	/**
	 * Remove a word from the word list that is used for word coverage
	 * calculation
	 * 
	 * @param index
	 *            Index of the word that should be removed
	 */

	public void removeWordFromWordList(int index) {
		if (wordList == null)
			return;

		if (index > wordList.size() - 1)
			return;

		wordList.remove(index);
	}

	/**
	 * Check if a word is already in the word list that is used for word
	 * coverage calculation
	 * 
	 * @param word
	 *            Word that should be searched
	 * @return Boolean result
	 */

	public boolean wordListContains(String word) {
		if (wordList == null)
			return false;

		return wordList.contains(word);
	}

	/**
	 * Check if the word list that is used for word coverage calculation is
	 * empty
	 * 
	 * @return Boolean result
	 */

	public boolean wordListExists() {
		if (getWordList().size() <= 0)
			return false;

		return true;
	}

	/**
	 * Remove all words from he word list that is used for word coverage
	 */

	public void clearWordList() {
		if (wordList == null)
			return;

		wordList.clear();
	}

	/**
	 * Getter for the path where the *.tabi project file is located
	 * 
	 * @return Absolute path to *.tabi file
	 */

	public String getSavePath() {
		if (savePath == null || savePath.length() <= 0)
			return new String();

		return savePath;
	}

	/**
	 * Setter for he path where the *.tabi project file is located
	 * 
	 * @param savePath
	 *            New path
	 */

	public void setSavePath(String savePath) {
		this.savePath = savePath;
	}

	/**
	 * Getter for corpus
	 * 
	 * @return Corpus
	 */

	public String getCorpus() {
		if (corpus == null)
			return new String();

		return corpus;
	}

	/**
	 * Setter for corpus
	 * 
	 * @param corpus
	 *            New corpus
	 */

	public void setCorpus(String corpus) {
		this.corpus = corpus;
	}

	/**
	 * Get language of the corpus
	 * 
	 * @return Language
	 */

	public Language getTextLanguage() {

		if (textLanguage == null)
			return Language.en;

		return textLanguage;
	}

	/**
	 * Setter for language of the corpus
	 * 
	 * @param textLanguage
	 *            New Language
	 */

	public void setTextLanguage(Language textLanguage) {
		this.textLanguage = textLanguage;
	}

}
